package com.wzb.mybatisplus.bitaction.model;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Blockcypher implements GetManeyStrategy{
    private static final String BASE_URL = "https://api.blockcypher.com/v1/btc/main/addrs/";
    @Override
    public String getBalanceForAddresses(String adress) {
        try {

            // 将地址列表转换为逗号分隔的字符串
//            String addressString = "1HQ3Go3ggs8pFnXuHVHRytPCq5fGG8Hbhx";

            URL url = new URL(BASE_URL + adress+"/balance");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            return response.toString();

        } catch (Exception e) {
            try {
                Thread.sleep(10);
            }catch (Exception e1){}
//            Thread.sleep(1000);
//            e.printStackTrace();
            return null;
        }

    }

    public static void main(String[] args) {
        List<String> lines = new ArrayList<>();

        try (BufferedReader br = new BufferedReader(new FileReader("D:\\btc\\miyao\\findGy.txt"))) {
            String line;
            while ((line = br.readLine()) != null) {
                lines.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 打印结果
        lines.forEach(System.out::println);
    }
}
